using System;
using Engine.Particles.Interfaces;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Engine.Particles.Effects
{
    public class MouseTrailEffect : IParticleEffect
    {
        private Particle _particle;
        private bool _effectCreated;

        public bool HasEnded
        {
            get { return _particle.TimeToLive <= 0; }
        }

        public Texture2D Texture { get; set; }
        public Vector2 EmitterLocation {get; set; }

        private Random _random;
        public MouseTrailEffect()
        {
            _random = new Random();
        }
        public static MouseTrailEffect Create(Texture2D texture, Vector2 emitterLocation)
        {
            return new MouseTrailEffect() {Texture = texture, EmitterLocation = emitterLocation};
        }
        public void Update(GameTime gameTime)
        {
            if (!_effectCreated)
            {
                var velocity = new Vector2(
                               1f * (float)(_random.NextDouble() * 2 - 1) * .1f,
                               1f * (float)(_random.NextDouble() * 2 - 1)) * .1f;

                _particle = Particle.Create(Texture, EmitterLocation, velocity, 0, 1, Color.Blue, 1, 50,Vector2.Zero,Vector2.Zero);
            }
            _effectCreated = true;

            _particle.Update(gameTime);
        }
        public void Draw(SpriteBatch spriteBatch)
        {
            _particle.Draw(spriteBatch);
        }
    }
}